package com.qf.openapi.web.master.interceptor;

import com.qf.openapi.web.master.utils.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object user = session.getAttribute(Constants.SESSION_USER_KEY);
        if (user == null) {
            response.sendRedirect("/ssm2202/view/login.html");
            return false;
        }
        return true;
    }
}
